package com.yunxi.controller.eai;

import com.alibaba.fastjson.JSON;
import com.yunxi.baseDataToHub.pojo.iam.IamStaff;
import com.yunxi.baseDataToHub.pojo.sap.*;
import com.yunxi.core.web.ApiResult;
import com.yunxi.eai.pojo.sap.VehiclePriceVo;
import com.yunxi.baseDataToHub.service.sap.SapDubboService;
import com.yunxi.eai.pojo.esb.EsbVO;
import com.yunxi.eai.pojo.iam.StaffVO;
import com.yunxi.eai.service.esb.ESBService;
import com.yunxi.ups.pojo.PartsAllotVO;
import com.yunxi.ups.pojo.PartsInventoryVO;
import com.yunxi.ups.pojo.PartsOrderVO;
import com.yunxi.ups.service.Ups2SapDubboService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.dozer.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by Administrator on 2019/5/30.
 */
@RestController
@RequestMapping("/esb/api")
@Api(tags = "esb:manage", description = "接收esb信息")
public class SAPController {

    @Autowired
    private SapDubboService sapDubboServiceImpl;

    @Autowired
    private ESBService esbService;

    @Autowired
    private Ups2SapDubboService Ups2SapDubboServiceImpl;
//    @Autowired
//    private Mapper dozerMapper;

    @PostMapping("/savePartnerInfoToSap")
    @ApiOperation(value = "渠道主数据")
    public Object savePartnerInfoToSap(@RequestBody PartnerInfoVO partnerInfoVO) throws Exception {

        Object object=sapDubboServiceImpl.savePartnerInfoToSap(partnerInfoVO);
        return object;
    }

  /*  @PostMapping("/sendVehiclePriceToSap")
    @ApiOperation(value = "整车价格维护")
    public Object sendVehiclePriceToSap(@RequestBody VehiclePriceVo vehiclePriceVo) throws Exception {

        Object object=sapDubboServiceImpl.sendVehiclePriceToSap(vehiclePriceVo);
        return object;
    }*/

    @PostMapping("/sendVehicleBatchOrderToSap")
    @ApiOperation(value = "批售订单")
    public Object sendVehicleBatchOrderToSap(@RequestBody VehicleBatchOrderVO vehicleBatchOrderVO) throws Exception {

        Object object=sapDubboServiceImpl.sendVehicleBatchOrderToSap(vehicleBatchOrderVO);
        return object;
    }
    @PostMapping("/sendVehiclePriceCountToSap")
    @ApiOperation(value = "价格试算")
    public Object sendVehiclePriceCountToSap(@RequestBody VehiclePriceCountVo vehiclePriceCountVo) throws Exception {

        Object object=sapDubboServiceImpl.sendVehiclePriceCountToSap(vehiclePriceCountVo);
        return object;
    }


    @PostMapping("/receiveVehicleDelivery")
    @ApiOperation(value = "接收SAP整车外向发运单")
    public Object findData(@RequestBody EsbVO esbVO) throws Exception {

        Object object=esbService.distributeEsb(esbVO);
        return object;
    }

    @PostMapping("/sendVehicleBatchOrderModifyPms2Sap")
    @ApiOperation(value = "批售订单修改")
    public ApiResult sendVehicleBatchOrderModifyPms2Sap(@RequestBody VehicleBatchOrderModifyVO vehicleBatchOrderModifyVO) throws Exception {
        ApiResult apiResult = sapDubboServiceImpl.sendVehicleBatchOrderModifyPms2Sap(vehicleBatchOrderModifyVO);
        return apiResult;
    }


    @PostMapping("/sendDebitCreditPms2Sap")
    @ApiOperation(value = "借贷项请求接口")
    public ApiResult sendDebitCreditPms2Sap(@RequestBody DebitCreditVO debitCreditVO) throws Exception {
        ApiResult apiResult = sapDubboServiceImpl.sendDebitCreditPms2Sap(debitCreditVO);
        return apiResult;
    }

    @PostMapping("/sendRebateAmountPms2Sap")
    @ApiOperation(value = "返利发放金额同步接口")
    public ApiResult sendRebateAmountPms2Sap(@RequestBody RebateAmountVO rebateAmountVO) throws Exception {
        ApiResult apiResult = sapDubboServiceImpl.sendRebateAmountPms2Sap(rebateAmountVO);
        return apiResult;
    }
    @PostMapping("/findPartnerFundBySap")
    @ApiOperation(value = "渠道資金")
    public ApiResult findPartnerFundBySap(@RequestBody PartnerFundVO partnerFundVO) throws Exception {
        ApiResult apiResult = sapDubboServiceImpl.findPartnerFundBySap(partnerFundVO);
        return apiResult;
    }

    @PostMapping("/findpartnerFundDetailBySap")
    @ApiOperation(value = "渠道資金明細")
    public ApiResult findpartnerFundDetailBySap(@RequestBody PartnerFundDetailVO partnerFundDetailVO) throws Exception {
        ApiResult apiResult = sapDubboServiceImpl.findpartnerFundDetailBySap(partnerFundDetailVO);
        return apiResult;
    }

    @PostMapping("/findPartneFundUPS2SAP")
    @ApiOperation(value = "渠道配件账户资金")
    public ApiResult findPartneFundUPS2SAP(String var1) throws Exception {
        ApiResult apiResult = Ups2SapDubboServiceImpl.findPartneFundUPS2SAP(var1);
        return apiResult;
    }

    @PostMapping("/findPartsRepertoryUPS2SAP")
    @ApiOperation(value = "配件库存")
    public ApiResult findPartsRepertoryUPS2SAP(String var1) throws Exception {
        ApiResult apiResult = Ups2SapDubboServiceImpl.findPartsRepertoryUPS2SAP(var1);
        return apiResult;
    }

    @PostMapping("/sendPartsOrderUPS2SAP")
    @ApiOperation(value = "配件订单提交")
    public ApiResult sendPartsOrderUPS2SAP(@RequestBody PartsOrderVO var1) throws Exception {
        ApiResult apiResult = Ups2SapDubboServiceImpl.sendPartsOrderUPS2SAP(var1);
        return apiResult;
    }
    @PostMapping("/sendPartsAllotUPS2SAP")
    @ApiOperation(value = "配件调拨")
    public ApiResult sendPartsAllotUPS2SAP(@RequestBody PartsAllotVO var1) throws Exception {
        ApiResult apiResult = Ups2SapDubboServiceImpl.sendPartsAllotUPS2SAP(var1);
        return apiResult;
    }

    @PostMapping("/sendPartsInventoryUPS2SAP")
    @ApiOperation(value = "配件入库")
    public ApiResult sendPartsInventoryUPS2SAP(@RequestBody PartsInventoryVO var1) throws Exception {
        ApiResult apiResult = Ups2SapDubboServiceImpl.sendPartsInventoryUPS2SAP(var1);
        return apiResult;
    }
    @PostMapping("/testDozerConvert")
    @ApiOperation(value = "测试类之间转换")
    public String testDozerConvert(){

//        //测试简单的类映射
//        StaffVO staffVO = new StaffVO();
//        staffVO.setAccountNo("222111");
//        IamStaff iamStaff = dozerMapper.map(staffVO,IamStaff.class);
//        System.err.println(JSON.toJSON(iamStaff));

//        测试类中含list对的映射
       /* PartnerVO partnerVO = new PartnerVO();
        partnerVO.setPartnerCode("22222");
        PartnerTypeVO partnerTypeVO1=new PartnerTypeVO();
        partnerTypeVO1.setBusinessCode("aaaa");
        List<PartnerTypeVO> list = new ArrayList<>();
        list.add(partnerTypeVO1);
        PartnerTypeVO partnerTypeVO2=new PartnerTypeVO();
        partnerTypeVO2.setBusinessCode("bbbb");
        list.add(partnerTypeVO2);
        partnerVO.setPartnerTypeVOList(list);

        AccountGroupVO accountGroupPropVO = dozerMapper.map(partnerVO, AccountGroupVO.class);
        System.err.println(JSON.toJSON(accountGroupPropVO));*/

        return null;
    }
}
